﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Pub;

namespace LZQXT.Test
{
    public partial class FMain : Form
    {

        public List<Form> flst = new List<Form>();
        public Form ftmp = new Form();


        public FMain()
        {
            InitializeComponent();
        }


        public void addNode()
        {
            int i = 0;
            foreach (Form f1 in flst)
            {
                TreeNode tnode = new TreeNode();
                tnode.Text = f1.Text;
                tnode.ImageIndex = i;
                tnode.SelectedImageIndex = i;
                treeView1.Nodes.Add(tnode);

                i++;
            }
        }

        //设置窗体父容器
        public void SetParentI(Form f1, Control c1)
        {
            ftmp.Hide();
            f1.TopLevel = false;
            f1.FormBorderStyle = FormBorderStyle.None;
            f1.Parent = c1;
            f1.Dock = DockStyle.Fill;
            f1.Show();
            ftmp = f1;
        }

        private void FMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!CPub.MsgBox("确定要退出吗？", "退出"))
            {
                e.Cancel = true;
            }
        }

        private void FMain_Load(object sender, EventArgs e)
        {
            panel1.Dock = DockStyle.Fill;
            addNode();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            int i_btn = 0;
            if (sender is ToolStripButton) i_btn = Convert.ToInt32(((ToolStripButton)sender).Tag);

            switch (i_btn)
            {
                case 1:
                    treeView1.Visible = !treeView1.Visible;
                    splitter1.Visible = treeView1.Visible;
                    break;
                case 2:
                    Close();
                    break;
                case 3:
                    Program.fdbinit.ShowDialog();
                    break;
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            foreach (Form f1 in flst)
            {
                if (f1.Text == treeView1.SelectedNode.Text)
                {
                    SetParentI(f1, panel1);
                }
            }
        }

    }
}